package cn.taqu.es.controller;

import cn.taqu.es.controller.request.SearchDataBySqlRequest;
import cn.taqu.es.controller.request.UpdateByIdRequest;
import cn.taqu.es.util.ElasticSearchUtil;
import cn.taqu.es.util.EsPage;
import com.google.gson.JsonObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

@RequestMapping("es")
@Controller
public class ESController {

    @Autowired
    private ElasticSearchUtil elasticSearchUtil;


    @RequestMapping(value = "/searchDataBySql", method = RequestMethod.POST)
    @ResponseBody
    public EsPage searchDataBySql(@RequestBody SearchDataBySqlRequest request) throws Exception {
        return elasticSearchUtil.searchBySql(request.getPage(), request.getSize(), request.getSql());
    }


    @RequestMapping(value = "/update", method = RequestMethod.POST)
    @ResponseBody
    public String searchDataBySql(@RequestBody UpdateByIdRequest request) throws Exception {
        return elasticSearchUtil.update(request.getIndex(), request.getType(), request.getId(), request.getJson());
    }

    @RequestMapping(value = "/deleteIndex")
    @ResponseBody
    public JsonObject deleteIndex() {

        return null;
    }

}
